import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class sever {
    private DatagramSocket socket = null;
    public sever(int port) throws SocketException {
        this.socket = new DatagramSocket(port);
    }
    public void start() throws IOException {
        while (true){
            System.out.println("服务器启动");
            //接收数据报
            DatagramPacket resquestpage = new DatagramPacket(new byte[4090],4090);
            socket.receive(resquestpage);

            //处理数据报
            String request = new String(resquestpage.getData(),0,resquestpage.getLength());
            String reqonse = process(request);

            //将处理完的数据打包成数据报,然后发送回去
            DatagramPacket responsePage = new DatagramPacket(reqonse.getBytes(),reqonse.getBytes().length,
                    resquestpage.getSocketAddress());
            socket.send(responsePage);
        }
    }
    public String process(String request) {
        return request;
    }
    public static void main(String[] args) throws IOException {
        sever sever1 = new sever(9090);
        sever1.start();
    }
}
